﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;

namespace ScrumFactory.Windows.Helpers.Converters {

    [ValueConversion(typeof(string), typeof(Brush))]
    public class ColorConverter : IValueConverter {


        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            if (value == null)
                return null;
            Color? c = System.Windows.Media.ColorConverter.ConvertFromString(value.ToString()) as Color?;
            if (c == null)
                return null;
            return new SolidColorBrush((Color)c);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            SolidColorBrush color = value as SolidColorBrush;
            if (color == null)
                return null;
            // ugly
            if (color.Equals(Colors.Crimson))
                return "Crimson";
            if (color.Equals(Colors.CornflowerBlue))
                return "CornflowerBlue";
            if (color.Equals(Colors.Gold))
                return "Gold";
            if (color.Equals(Colors.Black))
                return "Black";
            if (color.Equals(Colors.MediumSeaGreen))
                return "MediumSeaGreen";
            if (color.Equals(Colors.Silver))
                return "Silver";
            if (color.Equals(Colors.Transparent))
                return "Transparent";
            if (color.Equals(Colors.LightBlue))
                return "LightBlue";
            if (color.Equals(Colors.Khaki))
                return "Khaki";
            return null;
            
        }
    }
}
